# -- coding: utf-8 --
import threading

import threading

sum = 0
tmp = 0

def thread_entry():
    global sum, tmp

    for i in range(1000 * 1000):
        lock.acquire()  # 获取锁
        tmp = sum + 1
        sum = tmp
        lock.release()  # 释放锁

lock = threading.Lock() # 初始化锁
t0 = threading.Thread(target = thread_entry, args = ())
t1 = threading.Thread(target = thread_entry, args = ())
t0.start()
t1.start()
t0.join()
t1.join()
print('sum =', sum)